<!doctype html>
<html>
<head>
	<meta charset="utf-8"><meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<title>艺考圈</title>
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
</head>
<body>
<div id="root">
	<div class="app_warp">
		<div class="app_head">
			<span class="left back"></span>
			<span class="name">心得详情</span>
			<span class="right hide" tapmode onclick="deleteThis()">删除</span>
		</div>
		<div id="artcircle_view" class="app_main">
			<div id="nocontent" class="nocontent animated fadeInUp">
				<img src="../../lib/img/loading.gif" class="minimize" alt="">
				<div class="text minimize">
					准备数据
				</div>
			</div>
		</div>

	</div>
</div>

<script id="artcircle_list_template" type="text/html">
	<%
	var _data_ = data[0];
	%>
	<div class="space"></div>
	<div class="app_box transparent animated fadeInUp">
		<div class="box_cont">
			<ul class="list_item sociality_list clearfix">

				<li>
					<img class="sociality_pic imgcache" src="<%:=img%>" data_src="<%:=_data_.avatar%>" alt="">
					<span class="sociality_username<%if(_data_.isMechanism==true){%> jigou<%}%>">
						<%:=_data_.author%>
					</span>
					<span class="sociality_date">
						<%:=_data_.date%>
					</span>
					<span class="sociality_zan <%:=_data_.zan.end===true?'active':'unactive'%>" tapmode onclick="zan(this)">
						<%:=_data_.zan.num%>
					</span>
					<span class="sociality_comment">
						<%if(_data_.comment!==null){%>
							<%:=_data_.comment.length%>
						<%}else{%>
							0
						<%}%>
					</span>
					<%if(_data_.intro!==null){%>
					<div class="sociality_cont clearfix">
						<%:=_data_.intro%>
					</div>
					<%}%>
					<%if(_data_.pics!==null){%>
					<div class="sociality_imgs clearfix" tapmode onclick="viewImg(this)">
						<%for(var j in _data_.pics) { var _pics_ = _data_.pics[j]%>
						<img class="imgcache" src="<%:=img%>" data_src="<%:=_pics_.thumb%>" picture="<%:=_pics_.picture%>" alt="">
						<%}%>
					</div>
					<%}%>
				</li>
			</ul>
		</div>
	</div>

	<%
		if(_data_.comment!==null){
	%>

		<ul class="replys animated fadeIn hide">
			<%
				for(var i in _data_.comment){
					var item = _data_.comment[i]
			%>
			<li data_cid="<%:=item.id%>" data_username="<%:=item.user%>" data_uid="<%:=item.uid%>" data_self="<%:=(item.self===true?1:0)%>">
				<span class="username" tapmode onclick="reply(this)">
					<%:=item.user%>
				</span>
				<%if(item.reply_uid!==null){%>
				<span class="reply_username " data_replyuid="<%:=item.reply_uid%>" tapmode onclick="replyUser(this)">
					@<%:=item.reply_name%>
				</span>
				<%}%>
				<span class="intro" tapmode onclick="reply(this)">
					: <%:=item.intro%> <em><%:=item.date%></em>
				</span>
			</li>
			<%
				}
			%>
		</ul>

	<%
		}
	%>

</script>

<script>
	var
		viewImg = function (obj) {
			var data=[],
				obj = $(obj).find('img');
			if(obj.length>0){
				for(var i =0;i<obj.length;i++){
					data.push(obj.eq(i).attr('picture'));
				}
				_$.img.view(data);
			}
		},
		replyArtcircle_ajaxCall = function (data) {
			if (data === null) {
				api.toast({
					msg: '删除成功'
				});
				api.execScript({
					name:'xinde',
					script:'initXinde()'
				})
				$('#artcircle_view,.commentline').fadeOut();
				_$.sleep(function(){
					api.closeWin();
				},1500);
			} else if (data.status === 200) {
				_$.template('artcircle_list_template', {
					'data': data.data,
					'img': _$.imgCache.default
				}, function (html) {
					$('#artcircle_view').html(html);
					_$.imgCache.load();
					_$.sleep(function () {
						$('.replys').removeClass('hide');
					}, 500)
				})
				dataUpdate(data);
			} else {
				api.toast({
					msg: '抱歉，未能得到数据'
				})
			}
		},
		deleteThis=function () {
			api.actionSheet({
				cancelTitle: '取消',
				buttons: ['删除']
			}, function (ret, err) {
				if (ret.buttonIndex == 1) {
					_$.ajax({
						interface:'deleteMood',
						data:{
							mid:api.pageParam.mid
						},
						call:function(data){
							if(data.status===200){
								replyArtcircle_ajaxCall(null);
								api.execScript({
									name:'index',
									frameName:'artcircle',
									script:'deleteXinde('+api.pageParam.mid+')'
								})
							}else{
								api.toast({
									msg:data.msg
								})
							}
						}
					})
				} else {
					return;
				}
			});
		},
		dataUpdate=function(data){
			api.execScript({
				name: 'index',
				frameName:'artcircle',
				script: 'dataUpdate(' + JSON.stringify(data.data[0]) + ')'
			})
			api.execScript({
				name: 'xinde',
				script: 'dataUpdate(' + JSON.stringify(data.data[0]) + ')'
			})
		},
		zan=function(obj){
			var _self=$(obj);
			_$.ajax({
				interface:'sendArtcircleMood',
				data:{
					act:'agree',
					mid:api.pageParam.mid
				},
				call:replyArtcircle_ajaxCall
			})
		},
		getReplyIntro=function(obj){
			obj = $(obj).parent();
			return {
				cid:obj.attr('data_cid'),
				uid:obj.attr('data_uid'),
				name:obj.attr('data_username'),
				self:obj.attr('data_self')==1?true:false
			}
		},
		reply=function(obj){
			var option=getReplyIntro(obj);
			if(!option.self){//回复动作
				_$.sendComment('replyArtcircle',('回复'+option.name+'的心得'),api.pageParam.mid,option);
			}else{//删除动作
				api.actionSheet({
					cancelTitle: '取消',
					buttons: ['删除']
				}, function (ret, err) {
					if (ret.buttonIndex == 1) {
						_$.ajax({
							interface:'sendArtcircleMood',
							data:{
								act:'del_comment',
								mid:api.pageParam.mid,
								cid:option.cid
							},
							call:replyArtcircle_ajaxCall
						})
					} else {
						return;
					}
				});
			}
		},
		replyUser=function(obj){
			var option=getReplyIntro(obj);
				option.replyuid=$(obj).attr('data_replyuid');
			_$.sendComment('replyArtcircle',('回复'+$(obj).text()),api.pageParam.mid,option);
		},
		appready = function () {
			if(api.pageParam.isSelf===true){
				$('.app_head .right').removeClass('hide');
			}
			_$.ajax({
				interface:'getArtcircleIntro',
				data:{
					mid:api.pageParam.mid
				},
				call:function(data){
					if(data.status===200){
						_$.template('artcircle_list_template', {'data': data.data, 'img': _$.imgCache.default}, function (html) {
							$('#artcircle_view').html(html);
							_$.imgCache.load();
							$('.app_main').after('' +
								'<div class="commentline" tapmode onclick="_$.sendComment(\'replyArtcircle\',\'回复心得\','+api.pageParam.mid+',{cid:0,uid:0})">' +
								'   <div class="myinput">' +
								'       我来说两句' +
								'   </div>' +
								'   <div class="shoucang active">' +
								'       回复' +
								'   </div>' +
								'</div>');
							_$.sleep(function(){
								$('.replys').removeClass('hide');
							},500)
							dataUpdate(data);
						})
					}else{
						api.toast({
							msg:'抱歉，未能得到数据'
						})
						_$.sleep(function(){
							api.closeWin();
						},3000)
					}
				}
			})

		};

</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>